package com.lancoo.znbkxx.teacher.aibkGenerateTestPaper.aibkGenerateDialog

import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerAdapter
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerViewHolder
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.TempletSelectedTypeListInfor
import kotlinx.android.synthetic.main.aibk_adapter_item_itemcount_rank.view.*

class AibkTempletItemCountAdapter(
        val activity: AppCompatActivity,
        val templetSelectedTypeListInfor: TempletSelectedTypeListInfor,
        var indexA:Int
):KBaseRecyclerAdapter() {

    override fun getHolderView(parent: ViewGroup?, position: Int): View? {
        return LayoutInflater.from(activity)
                .inflate(R.layout.aibk_adapter_item_itemcount_rank, parent, false)
    }

    override fun onBindViewHolder(holder: KBaseRecyclerViewHolder, position: Int) {

        val itemCount = templetSelectedTypeListInfor[indexA].CountList[position].ItemNum
        val itemCountCheckedPosition = templetSelectedTypeListInfor[indexA].ItemCountCheckedPosition
        holder.convertView.BtnItemCount.text = itemCount.toString()
        holder.convertView.BtnItemCount.isSelected = itemCountCheckedPosition==position
        holder.convertView.BtnItemCount.setOnClickListener {

            templetSelectedTypeListInfor[indexA].ItemCountCheckedPosition = position
            clickItemCountListener!!.onClickItemCount(indexA,position)//执行小题数选择回调
            notifyDataSetChanged()
        }

    }

    override fun getItemCount(): Int {
        return templetSelectedTypeListInfor[indexA].CountList.size
    }

    override fun getItemViewType(position: Int): Int {
        return position
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    private var clickItemCountListener: OnClickItemCountListener? = null

    /*
   * 设置点击事件
   * */
    interface OnClickItemCountListener {
        fun onClickItemCount(indexA: Int,indexB: Int)
    }

    fun setClickItemCountListener(clickItemCountListener: OnClickItemCountListener?) {
        this.clickItemCountListener = clickItemCountListener
    }
}